package com.xiaotu.spider.maoyan.pipeline;

import com.xiaotu.common.model.MovieSoonModel;
import com.xiaotu.common.util.Constants;
import com.xiaotu.common.util.DataRedisKeyUtils;
import com.xiaotu.spider.APipeline;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;

/**
 * @类名 FilmSoonPipeline
 * @日期 2017年7月31日
 * @作者 高海军
 * @功能 即将上映电影数据pipeline
 */
@Component("FilmSoonPipeline")
public class FilmSoonPipeline extends APipeline
{
    @Override
    protected void doProcess(ResultItems resultItems, Task task)
    {
        MovieSoonModel movie = resultItems.get(MovieSoonModel.class.getName());
        if (movie == null)
            return;

        String key = DataRedisKeyUtils.getKey(Constants.DataRedisKey.MOVIE_SOON_YYYYMMDD);
        cacheHandler.hSet(key, movie.getUrl(), movie);
        cacheHandler.setCacheTimeout(key);
    }

}